import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/entity/entities/lf_photo_entity.dart';
import 'package:largefriends/pages/lf_edit_profile/lf_edit_text/lf_edit_text_logic.dart';
import 'package:largefriends/pages/lf_edit_profile/lf_manage_photos/lf_manage_photos_logic.dart';
import 'package:largefriends/res/lf_color.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_fonts.dart';
import 'package:largefriends/res/lf_string_ext.dart';
import 'package:largefriends/res/lf_text_style.dart';
import 'package:largefriends/res/lf_widget_ext.dart';
import 'package:largefriends/widgets/custom_cache_image.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';
import 'package:largefriends/widgets/lf_location_widget.dart';

import '../../config/lf_route.dart';
import '../../config/lf_type_config.dart';
import '../../res/strings/lf_strings.dart';
import '../../utils/lf_scroll_behavior.dart';
import '../../widgets/lf_multi_picker.dart';
import '../../widgets/lf_single_picker.dart';
import 'lf_edit_basic/lf_edit_basic_logic.dart';
import 'lf_edit_profile_logic.dart';

class LfEditProfilePage extends StatefulWidget {
  const LfEditProfilePage({super.key});

  @override
  State<LfEditProfilePage> createState() => _LfEditProfilePageState();
}

class _LfEditProfilePageState extends State<LfEditProfilePage> {
  final logic = Get.put(LfEditProfileLogic());

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: lfAppBar(
              leadingCallback: () {
                Get.back();
              },
              actions: [
                InkWell(
                  child: Container(
                    alignment: Alignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 16.w),
                    child: Text(
                      'Preview',
                      style: lfTextStyle(sp: 15.sp, fontFamily: fontBold),
                    ).shadeMask,
                  ),
                  onTap: () {
                    Get.toNamed(LFRoute.pathProfileDetail, arguments: {
                      'uid': logic.authService.currentAccount!.userId,
                      'userEntity': logic.authService.currentAccount!
                    });
                  },
                )
              ]),
          body: GetBuilder<LfEditProfileLogic>(
            builder: (logic) {
              return ScrollConfiguration(
                behavior: LfScrollBehavior(),
                child: CustomScrollView(
                  slivers: [
                    _photoWidget().sliverBox,
                    10.h.sliverBox,
                    10.h.sliverBox,
                    Center(
                      child: InkWell(
                        child: Text(
                          strAddPublicPrivatePhotos.tr,
                          style: lfTextStyle(
                              sp: 17.sp,
                              fontFamily: fontBold,
                              decoration: TextDecoration.underline,
                              color: colorFEFEFE),
                        ),
                        onTap: () {
                          toManagePhotos(photoType: PhotoType.public);
                        },
                      ),
                    ).sliverBox,
                    _baseInfo().sliverBox,
                    _location().sliverBox,
                    _textContent(
                        title: strHeadline.tr,
                        content:
                            logic.authService.currentAccount!.headline ?? "",
                        hint: strHeadlineTip.tr,
                        click: () {
                          toEditTextPage(type: EditTextType.headline);
                        }).sliverBox,
                    _textContent(
                        title: strAboutMe.tr,
                        content: logic.authService.currentAccount!.about ?? "",
                        hint: strAboutMeTip.tr,
                        click: () {
                          toEditTextPage(type: EditTextType.aboutMe);
                        }).sliverBox,
                    _textContent(
                        title: strAboutMyMatch.tr,
                        content:
                            logic.authService.currentAccount!.matchAbout ?? "",
                        hint: strAboutMyMatchTip.tr,
                        click: () {
                          toEditTextPage(type: EditTextType.aboutMatch);
                        }).sliverBox,
                    ..._detail(),
                    30.h.sliverBox,
                  ],
                ),
              );
            },
          ),
        ),
        onWillPop: () async {
          Get.back();
          return false;
        });
  }

  Widget _baseInfo() {
    return Padding(
      padding: EdgeInsets.only(top: 30.h, left: 16.w, right: 16.w),
      child: InkWell(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Expanded(
                    child: Text(
                  strBasic.tr,
                  style: lfTextStyle(
                      sp: 17.sp, fontFamily: fontBold, color: color514F62),
                )),
                Icon(Icons.chevron_right,color: color514F62,),
              ],
            ),
            10.h.sbh,
            Row(
              children: [
                Flexible(
                  child: Text(
                    logic.authService.currentAccount!.username.toUpperCase(),
                    style: lfTextStyle(sp: 16.sp, fontFamily: fontRegular,color: colorFEFEFE),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
                Text(
                  ", ${logic.authService.currentAccount!.getGenderAbb()}",
                  style: lfTextStyle(sp: 16.sp, fontFamily: fontRegular,color: colorFEFEFE),
                ),
                Text(
                  ", ${logic.authService.currentAccount!.age ?? ""}",
                  style: lfTextStyle(sp: 16.sp, fontFamily: fontRegular,color: colorFEFEFE),
                ),
                16.w.sbw,
              ],
            )
          ],
        ),
        onTap: () {
          toEditBasic();
        },
      ),
    );
  }

  Widget _location() {
    return Padding(
      padding: EdgeInsets.only(
        top: 30.h,
        left: 16.w,
        right: 16.w,
      ),
      child: InkWell(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Expanded(
                    child: Text(
                  strLocation.tr,
                  style: lfTextStyle(
                      sp: 17.sp, fontFamily: fontBold, color: color514F62),
                )),
                 Icon(Icons.chevron_right,color: color514F62,),
              ],
            ),
            10.h.sbh,
            Text(
              logic.authService.currentAccount!.getLiveIn(),
              style: lfTextStyle(sp: 16.sp, fontFamily: fontRegular,),
            )
          ],
        ),
        onTap: () {
          showLfLocationWidget(
            onConfirm: (value) {
              if (value.countryId !=
                      logic.authService.currentAccount!.location?.countryId ||
                  value.stateId !=
                      logic.authService.currentAccount!.location?.stateId ||
                  value.cityId !=
                      logic.authService.currentAccount!.location?.cityId) {
                logic.authService.updateUserProfile(data: {
                  'user[countryId]': value.countryId,
                  'user[stateId]': value.stateId,
                  'user[cityId]': value.cityId,
                });
              }
            },
            initLocation: logic.authService.currentAccount!.location,
            showAnyWhere: false,
          );
        },
      ),
    );
  }

  Widget _photoWidget() {
    return Container(
      width: ScreenUtil().screenWidth,
      height: ScreenUtil().screenWidth,
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Column(
        children: [
          Expanded(
            flex: 2,
            child: Row(
              children: [
                Expanded(
                  flex: 2,
                  child: _photoItem(0),
                ),
                6.w.sbw,
                Expanded(
                  flex: 1,
                  child: Column(
                    children: [
                      Expanded(
                        flex: 1,
                        child: _photoItem(1),
                      ),
                      6.h.sbh,
                      Expanded(
                        flex: 1,
                        child: _photoItem(2),
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
          6.h.sbh,
          Expanded(
            flex: 1,
            child: Row(
              children: [
                Expanded(
                  flex: 2,
                  child: Row(
                    children: [
                      Expanded(
                        flex: 1,
                        child: _photoItem(3),
                      ),
                      6.w.sbw,
                      Expanded(
                        flex: 1,
                        child: _photoItem(4),
                      )
                    ],
                  ),
                ),
                6.w.sbw,
                Expanded(
                  flex: 1,
                  child: _photoItem(5),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _photoItem(int index) {
    return LayoutBuilder(builder: (context, constants) {
      if (index == 0) {
        if (logic.publicPhotos.isNotEmpty) {
          return InkWell(
            child: SizedBox(
              child: Stack(
                children: [
                  CustomCacheImage(
                    imageUrl: logic.publicPhotos.first.url ?? "",
                    width: constants.maxWidth,
                    height: constants.maxHeight,
                    radius: 5.r,
                  ),
                  Align(
                    alignment: Alignment.bottomLeft,
                    child: Container(
                      decoration: BoxDecoration(
                        color: colorFF007F,
                        borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(5.r),
                            topRight: Radius.circular(5.r)),
                      ),
                      padding:
                          EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
                      child: Text(
                        strMain.tr,
                        style: lfTextStyle(sp: 13.sp, color: colorFEFEFE),
                      ),
                    ),
                  )
                ],
              ),
            ),
            onTap: () {
              toManagePhotos(photoType: PhotoType.public);
            },
          );
        } else {
          return InkWell(
            child: Container(
              width: constants.maxWidth,
              height: constants.maxHeight,
              decoration: BoxDecoration(
                color: color50F2A7BE,
                borderRadius: 5.r.radius,
              ),
              alignment: Alignment.center,
              padding: EdgeInsets.all(10.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    strAddMainPhoto.tr,
                    style: lfTextStyle(sp: 16.sp, fontFamily: fontMedium),
                  ),
                  10.h.sbh,
                  const Icon(Icons.add),
                ],
              ),
            ),
            onTap: () {
              logic.addPublicPhotos();
            },
          );
        }
      } else {
        LfPhotoEntity? entity;
        if (index < logic.publicPhotos.length) {
          entity = logic.publicPhotos[index];
        } else if (index <
            logic.publicPhotos.length + logic.privatePhotos.length) {
          entity = logic.privatePhotos[index - logic.publicPhotos.length];
        }
        if (entity != null) {
          return InkWell(
            child: SizedBox(
              width: constants.maxWidth,
              height: constants.maxHeight,
              child: Stack(
                children: [
                  CustomCacheImage(
                    imageUrl: entity.url ?? "",
                    width: constants.maxWidth,
                    height: constants.maxHeight,
                    radius: 5.r,
                  ),
                  entity.type == photoTypePrivate
                      ? Align(
                          alignment: Alignment.bottomLeft,
                          child: Container(
                            decoration: BoxDecoration(
                              color: colorFF007F,
                              borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(5.r),
                                  topRight: Radius.circular(5.r)),
                            ),
                            padding: EdgeInsets.symmetric(
                                horizontal: 6.w, vertical: 2.h),
                            child: Text(
                              strPrivate.tr,
                              style: lfTextStyle(sp: 13.sp, color: colorFEFEFE),
                            ),
                          ),
                        )
                      : 1.h.sbh,
                ],
              ),
            ),
            onTap: () {
              toManagePhotos(
                  photoType: entity!.type == photoTypePublic
                      ? PhotoType.public
                      : PhotoType.private);
            },
          );
        } else {
          return InkWell(
            child: Container(
              width: constants.maxWidth,
              height: constants.maxHeight,
              decoration: BoxDecoration(
                color: color50F2A7BE,
                borderRadius: 5.r.radius,
              ),
              child: const Icon(Icons.add),
            ),
            onTap: () {
              toManagePhotos(photoType: PhotoType.public);
            },
          );
        }
      }
    });
  }

  Widget _title(String title) {
    return Padding(
      padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 30.h),
      child: Text(
        title,
        style: lfTextStyle(sp: 17.sp, fontFamily: fontBold, color: color514F62),
      ),
    );
  }

  List<Widget> _detail() {
    List<Widget> items = List.empty(growable: true);
    items.add(_title(strPersonalDetail.tr).sliverBox);

    items.add(
      _detailItem(
        title: strHeight.tr,
        data: TypeConfig().getValueByKey(
            LfConfigTypeEnum.height, logic.authService.currentAccount!.height),
        click: () {
          _showHeightSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strBodyType.tr,
        data: TypeConfig().getValueByKey(
            LfConfigTypeEnum.body, logic.authService.currentAccount!.body),
        click: () {
          _showBodySheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strEthnicity.tr,
        data: TypeConfig().getValueByKey(LfConfigTypeEnum.ethnicity,
            logic.authService.currentAccount!.ethnicity),
        click: () {
          _showEthnicitySheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strReligion.tr,
        data: TypeConfig().getValueByKey(LfConfigTypeEnum.religion,
            logic.authService.currentAccount!.religion),
        click: () {
          _showReligionSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strLanguages.tr,
        data: TypeConfig().getValueByKey(LfConfigTypeEnum.language,
            logic.authService.currentAccount!.language),
        click: () {
          _showLanguageSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strEducation.tr,
        data: TypeConfig().getValueByKey(LfConfigTypeEnum.education,
            logic.authService.currentAccount!.education),
        click: () {
          _showEducationSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strOccupation.tr,
        data: TypeConfig().getValueByKey(LfConfigTypeEnum.occupation,
            logic.authService.currentAccount!.occupation),
        click: () {
          _showOccupationSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strSmoking.tr,
        data: TypeConfig().getValueByKey(
            LfConfigTypeEnum.smoke, logic.authService.currentAccount!.smoke),
        click: () {
          _showSmokeSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strDrinking.tr,
        data: TypeConfig().getValueByKey(
            LfConfigTypeEnum.drink, logic.authService.currentAccount!.drink),
        click: () {
          _showDrinkSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strChildren.tr,
        data: TypeConfig().getValueByKey(LfConfigTypeEnum.haveChildren,
            logic.authService.currentAccount!.haveChildren),
        click: () {
          _showHaveChildrenSheet();
        },
      ),
    );
    items.add(
      _detailItem(
        title: strPets.tr,
        data: TypeConfig().getValueByKey(
            LfConfigTypeEnum.pet, logic.authService.currentAccount!.pet),
        click: () {
          _showPetSheet();
        },
      ),
    );
    return items;
  }

  Widget _detailItem(
      {required String data,
      required String title,
      required Function() click}) {
    return InkWell(
      onTap: click,
      child: Padding(
        padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 16.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: lfTextStyle(sp: 16.sp, fontFamily: fontMedium),
            ),
            20.w.sbw,
            Expanded(
                child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Flexible(
                    child: Text(
                  data,
                  style: lfTextStyle(
                      sp: 16.sp, fontFamily: fontRegular, color: color514F62),
                  overflow: TextOverflow.ellipsis,
                )),
                const Icon(Icons.chevron_right)
              ],
            ))
          ],
        ),
      ),
    ).sliverBox;
  }

  Widget _textContent(
      {required String title,
      required String content,
      required String hint,
      required Function click}) {
    return Padding(
      padding: EdgeInsets.only(top: 30.h),
      child: InkWell(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                16.w.sbw,
                Expanded(
                    child: Text(
                  title,
                  style: lfTextStyle(
                      sp: 17.sp, fontFamily: fontBold, color: color514F62),
                )),
                 Icon(Icons.chevron_right,color: color514F62,),
                16.w.sbw,
              ],
            ),
            10.h.sbh,
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 16.w),
              child: Text(
                content.trim().replaceBreak.isNullOrEmpty == false
                    ? content.trim().replaceBreak ?? ""
                    : hint,
                maxLines: 3,
                overflow: TextOverflow.ellipsis,
                style: lfTextStyle(
                    sp: 16.sp,
                    fontFamily: fontRegular,
                    color: content.trim().replaceBreak.isNullOrEmpty
                        ? color514F62
                        : colorFEFEFE),
              ),
            )
          ],
        ),
        onTap: () {
          click.call();
        },
      ),
    );
  }

  final Map<String, dynamic> data = {};

  checkOtherOptions() {
    if (logic.authService.currentAccount!.height == 0 &&
        (data.containsKey('user[height]') == false)) {
      _showHeightSheet();
    } else if (logic.authService.currentAccount!.body == 0 &&
        (data.containsKey('user[body]') == false)) {
      _showBodySheet();
    } else if (logic.authService.currentAccount!.ethnicity == 0 &&
        (data.containsKey('user[ethnicity]') == false)) {
      _showEthnicitySheet();
    } else if (logic.authService.currentAccount!.religion == 0 &&
        (data.containsKey('user[religion]') == false)) {
      _showReligionSheet();
    } else if (logic.authService.currentAccount!.language == 0 &&
        (data.containsKey('user[language]') == false)) {
      _showLanguageSheet();
    } else if (logic.authService.currentAccount!.education == 0 &&
        (data.containsKey('user[education]') == false)) {
      _showEducationSheet();
    } else if (logic.authService.currentAccount!.occupation == 0 &&
        (data.containsKey('user[occupation]') == false)) {
      _showOccupationSheet();
    } else if (logic.authService.currentAccount!.smoke == 0 &&
        (data.containsKey('user[smoke]') == false)) {
      _showSmokeSheet();
    } else if (logic.authService.currentAccount!.drink == 0 &&
        (data.containsKey('user[drink]') == false)) {
      _showDrinkSheet();
    } else if (logic.authService.currentAccount!.haveChildren == 0 &&
        (data.containsKey('user[haveChildren]') == false)) {
      _showHaveChildrenSheet();
    } else if (logic.authService.currentAccount!.pet == 0 &&
        (data.containsKey('user[pet]') == false)) {
      _showPetSheet();
    } else {
      _updateProfile();
    }
  }

  void _showBodySheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.body,
      value: logic.authService.currentAccount!.body,
      title: strBodyType.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.body != value) {
          data['user[body]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showHeightSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.height,
      value: logic.authService.currentAccount!.height,
      title: strHeight.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.height != value) {
          data['user[height]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showEthnicitySheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.ethnicity,
      value: logic.authService.currentAccount!.ethnicity,
      title: strEthnicity.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.ethnicity != value) {
          data['user[ethnicity]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showReligionSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.religion,
      value: logic.authService.currentAccount!.religion,
      title: strReligion.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.religion != value) {
          data['user[religion]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showLanguageSheet() {
    showLfMultiPickerSheet(
      configTypeEnum: LfConfigTypeEnum.language,
      needPass: false,
      mustSelected: true,
      value: logic.authService.currentAccount!.language,
      title: strLanguages.tr,
      isDismissible: false,
      result: (value) async {
        if (logic.authService.currentAccount!.language != value) {
          data['user[language]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancel: () {
        _updateProfile();
      },
    );
  }

  void _showEducationSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.education,
      value: logic.authService.currentAccount!.education,
      title: strEducation.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.education != value) {
          data['user[education]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showOccupationSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.occupation,
      value: logic.authService.currentAccount!.occupation,
      title: strOccupation.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.occupation != value) {
          data['user[occupation]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      isDismissible: false,
      cancelCallback: () {
        _updateProfile();
      },
    );
  }

  void _showDrinkSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.drink,
      value: logic.authService.currentAccount!.drink,
      title: strDrinking.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.drink != value) {
          data['user[drink]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showSmokeSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.smoke,
      value: logic.authService.currentAccount!.smoke,
      title: strSmoking.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.smoke != value) {
          data['user[smoke]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showHaveChildrenSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.haveChildren,
      value: logic.authService.currentAccount!.haveChildren,
      title: strChildren.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.haveChildren != value) {
          data['user[haveChildren]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      cancelCallback: () {
        _updateProfile();
      },
      isDismissible: false,
    );
  }

  void _showPetSheet() {
    showLfSinglePicker(
      configTypeEnum: LfConfigTypeEnum.pet,
      value: logic.authService.currentAccount!.pet,
      title: strPets.tr,
      saveCallback: (value) async {
        if (logic.authService.currentAccount!.pet != value) {
          data['user[pet]'] = value;
          checkOtherOptions();
        } else {
          checkOtherOptions();
        }
      },
      isDismissible: false,
      cancelCallback: () {
        _updateProfile();
      },
    );
  }

  void _updateProfile() async {
    if (data.isEmpty) {
      return;
    }
    await logic.authService
        .updateUserProfile(
      data: data,
    )
        .whenComplete(() {
      data.clear();
    });
  }
}
